package notify

import (
	"log"
	"time"
)

//这里使用 channel演示 notify的 功能

type ReadChan <-chan bool
type WriteChan chan<- bool
type ReadWriteChan chan bool

func consumer(ch ReadChan, id int) {
	for {
		//var signal bool
		select {
		case _,acceptabe := <-ch:
			log.Printf("result msg = [ %v] \n",acceptabe)
			if acceptabe {
				log.Println(" channel is acceptable")
			}else {
				log.Println("channel is closed ..")
				goto breakLoop
			}
		case <-time.After(time.Second):
			log.Println("case default running...")
		}
	}
breakLoop:
	log.Printf("exit... [%v]", id)
}
func WriteTo(ch WriteChan) {
	ch <- true
}
func UseChannelCase() {

	ch := make(chan bool, 3)

	for i := 0; i < 10; i++ {
		if i <= 4 {
			ch <- true
		}
		if i == 5 {

			//close(ch)
		}
		go consumer(ch, i)
	}
	go func() {
		<-time.After(time.Second * 3)
		close(ch)
		//close(ch)
	}()
	time.Sleep(time.Minute)

}
